<?php

// $Id$

require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_type_attr_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_attr_type_dbc.class.php');
require_once($WSC->get_site_inc_dir().'modules/tangra_cms/classes/ci/tcms_ci_mod_dbc.class.php');


class TCMS_CI_Type_Attr_Deleter extends Tangra_Class {
	public static function delete(DB_Connection $dbc, $id, $hidden_inc_dir, $current_user_id) {
		$cita = new TCMS_CI_Type_Attr_DBC();
		if ($cita->load_by_id($dbc, $id)) {
			$ciat = new TCMS_CI_Attr_Type_DBC();
			if ($ciat->load_by_id($dbc, $cita->get_attr_type())) {
				$class_name = $ciat->get_class_name();
				if (!class_exists($class_name)) {
					require_once($hidden_inc_dir.$ciat->get_class_path());
				}

				$cia = new $class_name();

				$sql = $cia->get_sql_select_id_ci_for_ci_type_attr($id);
				$rez = $dbc->execute($sql);
				if ($rez_obj = $rez->fetch_object()) {
					$ci_mod = new TCMS_CI_Mod_DBC();
					$ci_mod->set_ci($rez_obj->CI);
					$ci_mod->set_modified_by($current_user_id);
					$ci_mod->save($dbc);


					$cia->delete($dbc, $rez_obj->ID);
				}
			}

			TCMS_CI_Type_Attr_DBC::delete($dbc, $id);
		}
	}
}

